const { upload } = require('./multer.js');
const deleteImage = require("./delete")
exports.create = (router) => {
  router.post('/image/update', upload.single('file'), async (req, res) => {
    var message = false
    try {
      const file = req.file;
      if (!file) {
        file.filename = null
      } else {
        message = await deleteImage.create(req.body.oldFilName);
      }
      res.send({
        message: message,
        fileName: file.filename
      })
    } catch (error) {
      res.status(500).send('Internal Server Error');
    }
  });
}
